package learning.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

	public LoginServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		String username=request.getParameter("username");
		String psw=request.getParameter("password");
		String remark=request.getParameter("remark");
		String constell=request.getParameter("constell");
		String sex=request.getParameter("sex");
		String[] hobby=request.getParameterValues("hobby");
		String hobbies=hobby.toString();
		if(username.equals("admin")&&psw.equals("admin")){
//			System.out.println("username:"+username+"\tpssword:"+psw+"\tremark:"+remark+"constellation:\t"+constell+"\tsex:"+sex+"\thobby:"+hobby);
			request.setAttribute("username", username);
			request.setAttribute("password", psw);
			request.setAttribute("remark", remark);
			request.setAttribute("constell", constell);
			request.setAttribute("sex", sex);
			request.setAttribute("hobbies", hobbies);
			RequestDispatcher dispatcher=request.getRequestDispatcher("login/success.jsp");
			dispatcher.forward(request, response);
		}else {
			RequestDispatcher dispatcher=request.getRequestDispatcher("login/fail.jsp");
			dispatcher.forward(request, response);
			
		}
			
			
	}
	public void init() throws ServletException {
	}

}
